import React from 'react'
import {Card, Divider} from "antd";
import {Link} from 'react-router-dom';
import {getLatestBlogComment} from '../../api/CommentAPI'

export default class Comment extends React.Component {


    constructor(props) {
        super(props);
        this.state = {list: []};
    }

    async componentDidMount() {
        let newComment = (await getLatestBlogComment(5)).data;
        let dataList = [];
        console.debug("----->",newComment)
        newComment.forEach((comment) => {
            dataList.push(
                <p>
                    <span key={comment.id}>{comment.nickName}</span> 发表在
                    <Link key={comment.blog.id}
                          to={'/blog/' + comment.blog.id}>{comment.blog.title.substring(0, 10)}.....</Link>
                </p>
            );
        });
        this.setState({list:dataList})

    }


    render() {
        return (
            <div>
                <Card style={{width: 300}}>
                    <Divider>最新发布的评论</Divider>
                    {this.state.list}
                </Card>
            </div>
        );
    };
}